package com.asialjim.wechat.spring.config.swagger;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * <h1><em>ASIAL JIM JAVA DOC</em></h1><hr/>
 * <h2>CLASS DESCRIPTION <i>[ NAME: BaseSwaggerConfig ]</i></h2><strong>
 * <p> base swagger Config
 * </strong><p><p><em>Copyright &copy; Asial Jim Co., LTD</em><hr/>
 *
 * @author Asial Jim &nbsp;&nbsp; <span>Email:<a href="mailto:asialjim@hotmail.com">asialjim@hotmail.com</a> &nbsp;&nbsp; <a href="asialjim@qq.com">asialjim@qq.com</a></span>
 * @version 1.0.0
 * @since 2021/3/18   &nbsp;&nbsp; JDK 8
 */
public abstract class BaseSwaggerConfig implements Swagger{

    protected SwaggerConfigProperty property;

    public abstract SwaggerConfigProperty initSwagger();

    public Docket createRestApi(){
        property = initSwagger();
        return new Docket(DocumentationType.SWAGGER_2)
                        .apiInfo(apiInfo())
                        .select()
                        .apis(RequestHandlerSelectors.basePackage(property.getBasePackage()))
                        .paths(PathSelectors.any())
                    .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder().title(property.getTitle()).description(property.getDescription()).termsOfServiceUrl("/").version(property.getVersion()).build();
    }
}
